using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
[CreateAssetMenu(menuName = "RPG Setup/Item Data/ItemDataList", fileName = "ItemDataList - ")]
[Serializable]
public class ItemListDataSO : ScriptableObject
{
    public ItemDataSO[] itemListData;

    public ItemDataSO GetItemData(string saveId)
        => itemListData.FirstOrDefault(item => item != null && item.saveId == saveId);
        
#if UNITY_EDITOR
    [ContextMenu("Auto-fill with all ItemDataSO")]
    public void CollectItemData()
    {
        string[] guids = AssetDatabase.FindAssets("t:ItemDataSO");
        itemListData = guids
                    .Select(guid => AssetDatabase.LoadAssetAtPath<ItemDataSO>(AssetDatabase.GUIDToAssetPath(guid)))
                    .Where(item => item != null)
                    .ToArray();
        EditorUtility.SetDirty(this);
        AssetDatabase.SaveAssets();
    }
#endif
}
